package com.sc.es.util;

import com.sc.es.entity.User;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author sc
 * Created on  2018/2/7
 */
public class LoginUserUtil {

    public static User load(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(principal!=null&&principal instanceof User){
            return (User) principal;
        }
        return null;
    }

    public static Integer getLoginUserId(){
        User user = load();
        if(user==null){
            return -1;
        }
        return user.getId();
    }
}
